﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Input;
using Passwords.Models;

namespace Passwords.Utils
{
    public class InputScopeToIndexConverter : IValueConverter
    {
        private static PhoneInputScopeNameValue[] available = new PhoneInputScopeNameValue[] {
            PhoneInputScopeNameValue.Default,
            PhoneInputScopeNameValue.Password,
            PhoneInputScopeNameValue.Memo,
            PhoneInputScopeNameValue.Date,
            PhoneInputScopeNameValue.Time,
            PhoneInputScopeNameValue.Number,
            PhoneInputScopeNameValue.Url,
            
            PhoneInputScopeNameValue.TelephoneNumber,
            PhoneInputScopeNameValue.Text
        };


        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            PhoneInputScopeNameValue scn = (PhoneInputScopeNameValue)value;
            return Array.IndexOf(available, scn);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int index = (int)value;
            if (index < 0 || index >= available.Length) index = 0;
            return available[index];
        }
    }
}
